package org.example.SlApi.RyxxApi;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.example.JycInfo;
import org.example.utils.ReadConf;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.example.CookieHandlingFilter.cookies;
import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;
import static org.example.SlApi.JbxxApi.JbxxbcApi.initJyclist;

public class Gg3API {//人员信息-高管财务一号信息保存
    public static void main(String[] args) throws IOException {
        gg3API();
    }
    private static List<JycInfo> JycList = new ArrayList<>();

    public static int gg3API() throws IOException {
        // 登录并更新cookies

        loginAndUpdateCookies();

        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI
        List<JycInfo> jycInfoList = initJyclist(); // 调用方法来获取列表
        if (!jycInfoList.isEmpty()) {
            JycInfo firstJycInfo = jycInfoList.get(0); // 获取列表中的第一个元素
            String pripid = firstJycInfo.getPripid(); // 使用实际的getter方法
            String sbid = firstJycInfo.getSbid();


            String data = "ywtSldj.do?method=saveZzjg&zzjg=S_ISEMPLOYEE_%3A_%2CS_POSITION_%3A490B_%2CS_ISAUDIT_%3A_%2CS_POSBRFORM_%3A04_%2CS_NAME_%3A%E5%BC%A0%E6%98%BE%E6%96%8C_%2CS_CERNO_%3A14230319730102615X_%2CS_SEX_%3A1_%2CS_COUNTRY_%3A156_%2CS_MOBTEL_%3A13568547855_%2CS_DOM_%3A%E6%9D%AD%E5%B7%9E%E5%95%8A%E5%95%8A%E5%95%8A%E7%BA%BA%E7%BB%87%E6%9C%89%E9%99%90%E8%B4%A3%E4%BB%BB%E5%88%86%E5%85%AC%E5%8F%B8_%2CS_CERTYPE_%3A10_%2CS_PRIPID_%3A"+pripid+"_%2CS_PERSON_ID_%3A&fddbr=S_PRIPID_%3A"+pripid+"_%2CS_EMAIL_%3A1747263120%40qq.com_%2CS_CERNO_%3A632821198008221029&pripid="+pripid+"&regorg=330000&sbid="+sbid+"&zmpath=&fmpath=&hzpath=&hkbpath=&zzjgSize=0&baseZheng=&baseFan=&baseHZ=&baseHKB=&clearCwry=0&sfzdrtype=0&csrftoken=&type=1&currentTab_ryxx=wsdsjs_box_id";
            Response response = givenWithCookies()

                    .header("Content-Type","multipart/form-data; boundary=----WebKitFormBoundary6FLIcZL51kmdTR9Y")


                    .log().all()
                    .post(data);
            System.out.println(cookies);
            int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
            System.out.println(statusCode);
            String body = response.getBody().asString();
            System.out.println(body);
            if (statusCode == 302) {

                String redirectUrl = response.getHeader("Location");
                System.out.println(redirectUrl);
                if (redirectUrl != null) {
                    Response finalResponse = givenWithCookies()
                            .log().all()
                            .when()
                            .get(redirectUrl);
                    int statusCode1 = finalResponse.getStatusCode();
                    System.out.println("Status Code: " + statusCode);


            return 0;

        }
        return 0;
    }}
        return 0;
    }}